﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="MKMDocument", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(MKMDocument))]
    public class MKMDocumentSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMKMDocument clazz;
        
        public MKMDocumentSerializer(IMKMDocument clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Type");
            if (clazz.Type!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "DocumentType");
                Writer.WriteString(clazz.Type.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Type");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Nr");
            if (clazz.Nr!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Nr.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Nr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Organisation");
            if (clazz.Organisation!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Organisation.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Organisation");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Type") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MKMDocument>Type");
                }
                clazz.Type = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.DocumentType(Reader.ReadElementString("Type"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MKMDocument>Type", Reader.LocalName);
            }
            if (Reader.LocalName=="Nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MKMDocument>Nr");
                }
                clazz.Nr = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Nr"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MKMDocument>Nr", Reader.LocalName);
            }
            if (Reader.LocalName=="Organisation") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>MKMDocument>Organisation");
                }
                clazz.Organisation = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Organisation"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>MKMDocument>Organisation", Reader.LocalName);
            }
        }
    }
}
